The node:worker_threads module enables the use of threads that execute JavaScript in parallel. Workers (threads) are useful for performing CPU-intensive JavaScript operations. They don't help much with I/O-intensive work. The Node.js built-in asynchronous I/O operations are more efficient than Workers can be.
Worker
isMainThread
parentPort
workerData
THERE ARE MORE
Unlike child_process or cluster, worker_threads can share memory. They do so by transferring ArrayBuffer instances or sharing SharedArrayBuffer instances.
You need to parse a large CSV file without blocking the event loop. How would you use a Worker thread to accomplish this, and what steps are required to get the parsed data back to the main thread?
If you create a Worker with new Worker('./worker.js') and forget to call worker.unref(), what effect does that have on process shutdown?
What happens if the Worker throws an uncaught exception? How does the main thread observe it?
Your new feature streams video frames to a client and you offload frame encoding to a Worker. Midway through testing, the encoding sometimes stalls and the main thread logs 'worker exited with code 1'. Walk me through how you'd debug this.
You need to share a large read‑only buffer between the main thread and multiple Workers. Which API would you use and what trade‑offs does it introduce?
Explain why using a Worker for a simple async I/O operation might be a bad idea, and how you would refactor it.
Our service processes thousands of concurrent image transformations. We currently spin up a new Worker per request, leading to high memory usage. How would you redesign the worker usage to improve throughput and resource efficiency?
Describe how you would implement a pool of reusable Workers that can handle variable‑size jobs while ensuring back‑pressure and graceful shutdown.
When deploying to a container orchestration platform, what considerations around Worker thread limits, CPU quotas, and process signals must you account for?
We are migrating a legacy monolith that uses child_process for CPU‑bound work to a microservice architecture. How would you evaluate moving to Worker threads across services, considering maintainability, observability, and cross‑team ownership?
Design a cross‑team strategy for standardizing Worker thread usage, including guidelines for error handling, logging, and shared memory, while allowing teams to opt‑in to custom implementations.
At scale, how would you monitor and alert on Worker thread health across hundreds of nodes, and what metrics would you prioritize?